<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin', 'admin', 0);
pc_base::load_sys_class('format', '', 0);
pc_base::load_sys_class('form', '', 0);

/**
 * 少儿报名推荐人管理
 * @author ASUS
 *
 */
class recommend extends admin{
	private $db;
	public $siteid;
	public $admin_userid;
	
	function __construct() {
		parent::__construct();
		$this->db = pc_base::load_model('reg_child_recommend_model');//加载少儿报名推荐人model
		$this->reg_child = pc_base::load_model('reg_child_model');//加载少儿报名推荐人model
		$this->siteid = $this->get_siteid();// 获取当前站点ID
		$this->admin_userid = param::get_cookie('userid');//获取当前登录的管理员ID
	}
	
	public function init() {
	    //查询出少儿报名主题表中所有的id、title并重构数据
	    $reg_child_title = $this->reg_child->select('','id,title');
	    $reg_child_name = array();
	    foreach ($reg_child_title as $key=>$value){
	        $reg_child_name[$value['id']] = $value['title'];
	    }
	    
	    //分页
		$page = $_GET['page'] ? intval($_GET['page']) : 1;
		
		//搜索
		$where = "";
		if (isset($_GET['search'])) {
			$name = trim($_GET['name']);
			$type = intval($_GET['type']);
			$is_pay = intval($_GET['is_pay']);
			$tel = $_GET['tel'];
			if($name){
			    $where .= "name like '%$name%' and ";
			}
			if($type){
			    $where .= " type =".$type.' and ';
			}
			if($tel){
			    $where .= " tel =".$tel.' and ';
			}
			//是否支付：是
			if($is_pay == 1){
			    $where .= " is_pay =".$is_pay.' and ';
			}
			//是否支付：否
			if($is_pay == 2){
			    $where .= " is_pay = 0 and ";
			}
		}
		$where .= "siteid = ".$this->siteid;
		$recommend = $this->db->listinfo($where,'id DESC',$page,10);
		$pages = $this->db->pages;
		include $this->admin_tpl('recommend_list');
	}
}